<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f2f5;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }
        .container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 2rem;
            text-align: center;
            max-width: 500px;
            width: 90%;
        }
        h1 {
            color: #1877f2;
            margin-bottom: 1rem;
        }
        .user-info {
            background-color: #e7f3ff;
            border-radius: 6px;
            padding: 1rem;
            margin-top: 1rem;
        }
        .user-info p {
            margin: 0.5rem 0;
        }
        .decoration {
            margin-top: 2rem;
            font-style: italic;
            color: #666;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>欢迎来到首页</h1>
    <div class="user-info">
        <p>用户名: <span id="username">加载中...</span></p>
        <p>登录时间: <span id="loginTime">加载中...</span></p>
    </div>
    <div class="decoration">
        <p>"生活就像一盒巧克力，你永远不知道下一颗是什么味道。"</p>
        <p>— 阿甘正传</p>
    </div>
</div>

<script>
    $(document).ready(function() {
        $.ajax({
            url: 'getUserInfo',  // 假设后端接口为 /getUserInfo
            method: 'GET',
            success: function(response) {
                $('#username').text(response.username);

                // 将时间戳转换为可读格式
                var date = new Date(response.timestamp);
                var formattedDate = date.toLocaleString('zh-CN', {
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: '2-digit',
                    minute: '2-digit',
                    second: '2-digit'
                });

                $('#loginTime').text(formattedDate);
            },
            error: function() {
                $('#username').text('获取失败');
                $('#loginTime').text('获取失败');
            }
        });
    });
</script>
</body>
</html>